<?php
session_start();
require_once "includes/config.php";

$sqlUser="select * from tbl_users where status=1";
$exeUser=mysql_query($sqlUser) or die($sqlUser);
while($arrUser=mysql_fetch_array($exeUser))
{

	$numTotalFeedback=mysql_num_rows(mysql_query("select * from tbl_feedback where comm_to='".$arrUser['user_id']."'"));
	
	$sum_of_positive=mysql_fetch_array(mysql_query("select SUM(points) as total_positive from tbl_feedback where comm_to='".$arrUser['user_id']."' and rate=1"));
	$sum_of_negative=mysql_fetch_array(mysql_query("select SUM(points) as total_negative from tbl_feedback where comm_to='".$arrUser['user_id']."' and rate=3"));													
	$totalTransaction=mysql_num_rows(mysql_query("select * from tbl_feedback where comm_to='".$arrUser['user_id']."' and rate!=2"));
	
	if($numTotalFeedback>0 && $totalTransaction>0 && $numTotalFeedback>=3)
	{
	  $feedback_rate=($sum_of_positive['total_positive']+$sum_of_negative['total_negative'])/$totalTransaction;
	
	  $current_rate = floor($feedback_rate);
	  if($current_rate<70)
	  {
		 mysql_query("update tbl_users set status=3 where user_id='".$arrUser['user_id']."'") or die(mysql_error());
	  }
	}
}
?>
